//
//  LGNavigationBar.swift
//  LGMusic
//
//  Created by 梁尚嘉 on 2017/4/10.
//  Copyright © 2017年 LimeGah. All rights reserved.
//

import UIKit

class LGNavigationBar: UIView {

    private var backItem:UIButton?
    private var indicator:UIImageView?

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.configure()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    public var currentIndex: UInt = 0 {
        didSet {
            if oldValue != currentIndex {
                self.indicator?.image = UIImage.init(named: "img_scenario_back_loading_\(currentIndex+1)")
            }
        }
    }


    private func configure() -> Void {

        let shadowView = UIImageView.init(image: UIImage.init(named: "img_scenarioplay_shadow"))
        self.addSubview(shadowView)
        shadowView.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(0)
        }

        self.backItem = UIButton.init()
        self.backItem?.setImage(UIImage.init(named: "bt_playpage_cancel_normal"), for: UIControlState.normal)
        self.backItem?.setImage(UIImage.init(named: "bt_playpage_cancel_press"), for: UIControlState.highlighted)
        self.addSubview(self.backItem!)
        self.backItem?.addTarget(self, action: #selector(LGNavigationBar.backAction), for: UIControlEvents.touchUpInside)
        self.backItem?.snp.makeConstraints({ (make) in
            make.left.equalTo(SM_SIZE(32))
            make.bottom.equalTo(SM_SIZE(-15))
        })

        self.indicator = UIImageView.init()
        self.addSubview(self.indicator!)
        self.indicator?.snp.makeConstraints({ (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.centerY.equalTo((self.backItem?.snp.centerY)!)
        })
    }

    @objc private func backAction() {
        SMNAVI_DISMISS { 

        }
    }
}
